package com.tr.rentcar.controller.houtai.base;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.common.FileUpload;
import com.tr.rentcar.model.bean.Friendlink;
import com.tr.rentcar.model.bean.PPT;
import com.tr.rentcar.model.dao.FriendDao;
import com.tr.rentcar.model.dao.PPTdao;

@WebServlet("/ppt")
@MultipartConfig(maxFileSize = 10 * 1024 * 1024)
public class Pptcontrollor extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			List<PPT> ppt = new PPTdao().getAll();
			req.setAttribute("ppt", ppt);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		req.getRequestDispatcher("/WEB-INF/jsp/houtai_ppt.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String Id = req.getParameter("id");
			Integer id = Integer.parseInt(Id);
			// 获取头像Part对象,上传图片
			Part part = req.getPart("tx");
			//String fileSavePath = "D:/Users/Administrator/git/rentcar/WebContent/statics/image/upload/ppt";
			String fileSavePath = "F:/git/rentcar/WebContent/statics/image/upload/ppt";
			String fileName = FileUpload.upload(part, fileSavePath);
			new PPTdao().updatetu(fileName, id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resp.sendRedirect(req.getContextPath() + "/ppt");

	}

}
